<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: create_pdf_download.php 33 2013-09-21 11:54:49Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 33 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:54:49 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');

$pdf = $db->db_query("SELECT bill_name FROM ".TABLE_ORDERS_PDF." WHERE order_id = '".(int)$_GET['oID']."' ");
$pdf_pfad = $pdf->fields['bill_name'];
$pdf_name = substr($pdf->fields['bill_name'], 15, strlen($pdf->fields['bill_name']));

$pdf_name = explode('/', $pdf->fields['bill_name']);
$result = array_reverse($pdf_name);
$pdf_name = $result[0];

if(file_exists($pdf_pfad)) {
	$fp = fopen($pdf_pfad, 'rb');
	$pdf = fread ($fp, filesize ($pdf_pfad));
	fclose($fp);
	
	header("Last-Modified: ".gmdate("D,d M Y H:i:s")." GMT");
	header("Cache-Control: no-cache, must-revalidate");
	header("Pragma: no-cache");
	header("Content-type: application/octet-stream");
	header("Content-Length: ".filesize($pdf_pfad));
	header("Content-Disposition: attachment; filename=\"".$pdf_name."\"");
	header("Content-type: application/pdf");
	
	echo $pdf;
} else
	echo 'Die PDF-Rechnung konnte nicht gefunden werden!';
?>